package com.bracketbird.client.gui.club.tournament;

import com.bracketbird.client.model.*;
import com.google.gwt.event.dom.client.*;
import com.bracketbird.clientcore.gui.*;
import com.bracketbird.clientcore.style.*;
import com.bracketbird.clientcore.util.*;

/**
 *
 */
public class PlayerComponent extends HorizontalComponent {

    private LabelComponent player;
    private final Member member;
    private PlayingTeamComponent parent;

    public PlayerComponent(PlayingTeamComponent tc, String playerName, Member m) {
        super();
        this.parent = tc;
        this.member = m;
        getPlayer().setText(playerName);

        ImageComponent img = new ImageComponent("deleteSmall.png");
        img.setTitle("Delete player");
        img.getImage().addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                parent.delete(PlayerComponent.this);
            }
        });

        img.getImage().addMouseOverHandler(MouseOver.POINTER);
        add(getPlayer(), new TextLayout(Vertical.MIDDLE).sizeSmall().colorBaseDark());
        add(img, new TextLayout(1,0,0,10,Vertical.MIDDLE));


    }


    public LabelComponent getPlayer() {
        if (player == null) {
            player = new LabelComponent("");
        }
        return player;
    }

    public Member getMember() { 
        return member;
    }

    public String getPlayerName() {
        return getPlayer().getLabel().getText();
    }
}